# -*- coding: utf-8 -*-
"""
| @brief 居民身份证号码校验,参考 http://www.ip33.com/shenfenzheng.html
| @author Zhichao Wu
| @date 2022-04-23 16:33:40
| @version 1.0.0
"""
from datetime import datetime
import unittest

# 身份证号码前面的17位数系数
WEIGHT = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2)
CHECK_CODE = ('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2')


def check_id_number(id_number: str) -> str:
    result = 0
    for i in range(len(WEIGHT)):
        result += int(id_number[i]) * WEIGHT[i]
    return CHECK_CODE[result % 11]


class IDCardTestCase(unittest.TestCase):
    def test_something(self):
        print(check_id_number('110100100001010059'))


if __name__ == '__main__':
    start_time = datetime.now()
    print("[%s]%s开始运行..." % (start_time.strftime('%Y-%m-%d %H:%M:%S.%f'), __file__))

    unittest.main()

    end_time = datetime.now()
    print(f"[{end_time.strftime('%Y-%m-%d %H:%M:%S.%f')}]{__file__}结束运行.")
    print(f"耗时:{end_time - start_time}")
